package com.zzxz.practicaltrainingsys.service.impl;

import com.zzxz.practicaltrainingsys.entity.Teacher;
import com.zzxz.practicaltrainingsys.mapper.TeacherMapper;
import com.zzxz.practicaltrainingsys.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public List<Teacher> getTeacher() {
        return teacherMapper.getTeacher();
    }

    @Override
    @Transactional
    public boolean updatePassword(Integer teacher_id, String teacher_password) {
        if (teacher_id == null || teacher_password == null || teacher_password.isEmpty()) {
            throw new IllegalArgumentException("教师ID或密码不能为空");
        }
        int affectedRows = teacherMapper.updatePassword(teacher_id, teacher_password);
        return affectedRows > 0;
    }

    @Override
    public boolean updateTeacher(Teacher teacher) {
        return teacherMapper.updateTeacher(teacher) > 0;
    }

    @Override
    public String getTeacherPassword(Integer teacherId) {
        return teacherMapper.findPasswordById(teacherId);
    }

    @Override
    public boolean insertTeacher(Teacher teacher) {
        return teacherMapper.insertTeacher(teacher) > 0;
    }

    @Override
    public boolean deleteTeacher(Integer teacher_id) {
        return teacherMapper.deleteTeacher(teacher_id) > 0;
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        return teacherMapper.deleteBatch(ids) > 0;
    }

    @Override
    public Teacher getTeacherById(Integer teacher_id) {
        return teacherMapper.getTeacherById(teacher_id);
    }

    @Override
    public Teacher loginTeacherById(Integer teacher_id) {
        return teacherMapper.loginTeacherById(teacher_id);
    }

    @Override
    public Teacher loginTeacherByPhone(String teacher_phone) {
        return teacherMapper.loginTeacherByPhone(teacher_phone);
    }

}